package org.proddevplm.business.resource;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.proddevplm.business.api.IAdapter;
import org.proddevplm.business.resource.constants.ResourceConstants;
import org.proddevplm.helpers.ManagerUtil;

public class ResourceAdapter implements IAdapter{

	@Override
	public Object adapt(int command, Map<String, Object> dataObject) {
		Object adaptedObject = null;
		Map<String, Object> resourceMap = new HashMap<String, Object>();
		
		switch (command){
		
		case ResourceConstants.UPDATE_RESOURCE:
			String uploadType = ManagerUtil.getStringFromReq(dataObject.get("uploadType"));
			resourceMap.put("uploadType", ManagerUtil.getStringFromReq(dataObject.get("uploadType")));
			
			resourceMap.put("fileName", ManagerUtil.getStringFromReq(dataObject.get("fileName")));
			System.out.println(resourceMap.get("fileName"));
			resourceMap.put("fileComments", ManagerUtil.getStringFromReq(dataObject.get("comments")));
			System.out.println(resourceMap.get("fileComments"));
			
			if("fromExternalTool".equals(uploadType)){
				resourceMap.put("activityName", ManagerUtil.getStringFromReq(dataObject.get("activityName")));
			}else if("fromResources".equals(uploadType)){
				resourceMap.put("fileStatus", ManagerUtil.getStringFromReq(dataObject.get("status")));
				System.out.println(resourceMap.get("fileStatus"));
				resourceMap.put("fileDevStage", ManagerUtil.getStringFromReq(dataObject.get("stage")));
				System.out.println(resourceMap.get("fileDevStage"));
			}else if("fromExternalToolApprover".equals(uploadType)){
				resourceMap.put("activityName", ManagerUtil.getStringFromReq(dataObject.get("activityName")));
			}
			
			adaptedObject = resourceMap;
			break;
			
		case ResourceConstants.DELETE_RESOURCE:
			
			resourceMap.put("resName", ManagerUtil.getStringFromReq(dataObject.get("resName")));
			
			adaptedObject = resourceMap;
			break;
		}
		
		return adaptedObject;
	}

}
